# -*- coding: utf-8 -*-

from odoo import models, fields, api


class Refund(models.Model):
    _name = 'tour.refund'
    _description = u'退款记录'

    order_id = fields.Many2one('tour.sale.order', string=u'订单')
    refund_number = fields.Char(string=u'退款单号', index=True)
    refund_fee = fields.Integer(string=u'申请退款金额(分)')
    wechat_user_id = fields.Many2one('tour.users', string=u'微信用户')
    refund_status = fields.Selection([('SUCCESS', u'退款成功'),
                              ('CHANGE', u'退款失败'), ('REFUNDCLOSE', u'退款关闭')], string=u'状态',
                             default='CHANGE')
    transaction_id = fields.Char(string=u'微信订单号')
    out_trade_no = fields.Char(string=u'商户订单号', index=True)
    out_refund_no = fields.Char(string=u'商户退款单号', index=True)
    total_fee = fields.Integer(string=u'订单金额(分)')
    settlement_refund_fee = fields.Integer(string=u'退款金额(分)')
    success_time = fields.Char(string=u'退款成功时间')
    refund_recv_accout = fields.Char(string=u'退款入账账户')
    refund_account = fields.Char(string=u'退款资金来源')
    refund_request_source = fields.Char(string=u'退款发起来源')


    @api.model
    def create(self, vals):
        vals['refund_number'] = self.env['ir.sequence'].next_by_code('tour.refund_number')
        return super(Refund, self).create(vals)
